package com.custom.action.condition;

import com.custom.action.condition.support.TableSupport;

/**
 * 默认条件构造实例对象
 * @author   Xiao-Bai
 * @since  2022/2/16 14:11
 **/
public class DefaultConditionWrapper<T> extends AbstractConditionWrapper<T, String, DefaultConditionWrapper<T>> {


    public DefaultConditionWrapper(Class<T> entityClass) {
        this.wrapperInitialize(entityClass);
    }

    public DefaultConditionWrapper(Class<T> entityClass, TableSupport tableSupport) {
        this.wrapperInitialize(entityClass, tableSupport);
    }

    DefaultConditionWrapper(ConditionWrapper<T> wrapper) {
        this.dataStructureInit();
        this.setEntityClass(wrapper.getEntityClass());
        this.setColumnParseHandler(wrapper.getColumnParseHandler());
        this.setTableSupport(wrapper.getTableSupport());
        this.setLastCondition(wrapper.getLastCondition());
        this.addCondition(wrapper.getFinalConditional());
        this.addParams(wrapper.getParamValues());
        this.setSelectColumns(wrapper.getSelectColumns());
        this.setPageParams(wrapper.getPageIndex(), wrapper.getPageSize());
        this.setPrimaryTable(wrapper.getPrimaryTable());
    }

    @Override
    protected DefaultConditionWrapper<T> getInstance() {
        return new DefaultConditionWrapper<>(getEntityClass());
    }

    @Override
    protected String paramTransColumn(String column) {
        return column;
    }

    /**
     * 转成lambda格式的构造器
     */
    public LambdaConditionWrapper<T> toLambda() {
        return new LambdaConditionWrapper<>(this);
    }

    public KtConditionWrapper<T> toKtWrapper() {
        return new KtConditionWrapper<>(this);
    }

}
